<script setup lang="ts">
import type { TableInstanceColumns } from '@/components/ProTable/type'
import { ExamApi } from '@/apis'
import { useRequest } from '@/hooks'

defineOptions({
  name: 'Exam',
})
const props = withDefaults(defineProps<Props>(), {
  examId: '',
})

interface Props {
  examId: string
}

const {
  loading,
  response: dataList,
  refresh: search,
} = useRequest(() => ExamApi.getQuestionList(props.examId))

const columns: TableInstanceColumns[] = [
  { title: '序号', dataIndex: 'questionIndex', slotName: 'questionIndex', width: 66 },
  { title: '题目类型', dataIndex: 'questionType', slotName: 'questionType' },
  { title: '模块', dataIndex: 'questionModule', slotName: 'questionModule' },
  { title: '知识点', dataIndex: 'knowledgePoints', slotName: 'knowledgePoints' },
  { title: '题目分数', dataIndex: 'score'},
  { title: '平均得分', dataIndex: 'averageScore'},
]
</script>

<template>
  <ProTable
    row-key="id"
    :data="dataList"
    :columns="columns"
    :loading="loading"
    :scroll="{ x: '100%', y: '100%', minWidth: 1000 }"
    :pagination="false"
    @refresh="search"
  >
    <template #questionType="{ record }">
      <CellDict :value="record.questionType" code="QuestionTypeEnum" />
    </template>
    <template #questionModule="{ record }">
      <CellDict :value="record.questionModule" code="QuestionModuleEnum" />
    </template>
  </ProTable>
</template>

<style lang="less" scoped></style>
